﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Think.Lenovo.Com.Models.Users;
using Think.Lenovo.Com.DataAccess.User;

namespace Think.Lenovo.Com.qiantai
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void Btn_Login_Click(object sender, EventArgs e)
        {
            try
            {
                String uname = this.UserName.Value;
                String upwd = this.UserPassword.Value;
                String vstr = this.ValidateString.Value;
                if (vstr.ToLower() != Session["LoginValidateCode"].ToString())
                {
                    Response.Write("<script type=\"text/javascript\">");
                    Response.Write("alert(\"验证码错误\")");
                    Response.Write("</script>");
                    return;
                }
                User u = new User();
                ViewUserModel umodel =u.GetUser(uname,upwd);
                if (umodel == null)
                {
                    Response.Write("<script type=\"text/javascript\">");
                    Response.Write("alert(\"用户名或密码错误\")");
                    Response.Write("</script>");
                    return;
                }
                else if (umodel.Id > 0) {
                    Session["User"] = umodel;
                    Response.Redirect("/home/userhome.aspx");
                    return;
                }
            }
            catch (Exception ex)
            {
                //记录日志文件
            }
        }
    }
}